package com.ml.mall.mapper.coupon;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ml.mall.bean.req.coupon.CouponQueryDto;
import com.ml.mall.bean.res.coupon.CouponQueryRes;
import com.ml.mall.bean.vo.coupon.CouponVo;
import com.ml.mall.bean.vo.coupon.UsableCouponVo;
import com.ml.mall.entity.coupon.SysCoupon;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysCouponMapper extends BaseMapper<SysCoupon> {

    int selectPageCountRes(@Param("dto")CouponQueryDto dto);
    List<CouponQueryRes> selectPageRes(@Param("dto") CouponQueryDto dto);

    /**
     * @description    :更新优惠券使用数量
     * @author         :zxm
     * @date           :2021/5/24
    **/
    @Update("update sys_coupon set use_amount = use_amount + 1 where is_delete = 0 and coupon_code = #{couponCode} ")
    int updateCouponUseAmount(@Param("couponCode") String couponCode);

    /**
     * 查询可用的全局优惠券；
     * @return java.util.List<com.ml.mall.bean.vo.coupon.UsableCouponVo>
     * @author Daizh
     * @date 2021/7/3 14:59
     */
    List<UsableCouponVo> selectUsableCoupon(@Param("vo") CouponVo vo);

    /**
     * 查询是否有全局优惠券
     * @return
     */
    UsableCouponVo  selectAdminCouppon();


    //通过订单号；卖家Id 查询订单相关的
    List<SysCoupon> selectCouponByOidAndSupplierId(@Param("oid") Long oid,@Param("supplierId") Long supplierId);

}